<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/list.css">
    <link rel="stylesheet" href="css/my_blog_list.css">
    <script src="js/jquery.min.js"></script>
    <style>
        
        .nav{
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
        }
        .container{
            padding-top: 80px;
            height: auto;
        }
        .container-right{
            width: auto;
        }
        .blog-pagnation-wrapper{
            height: 40px;
            margin: 16px 0;
            text-align: center;
        }
        .blog-pagnation-item{
            display: inline-block;
            padding: 8px;
            border: 2px solid #e8b267;
            color: #333;
            border-radius: 40%;
        }
        .blog-pagnation-item:hover{
            background: #ec7f3c;
            color: #fde0a2;
        }
        .blog-pagnation-item.actvie{
            background: #ec7f3c;
            color: #fde0a2;
        }

    </style>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo1.jpg" alt="">
        <span class="title">博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="myblog_list.html?type=all">主页</a>
        <a href="blog_add.html">写博客</a>
        <a href="login.html" id="login">登陆</a>
        <a href="login.html"onclick="log_out()">退出账号</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 右侧内容详情 -->
        <div class="container-right" style="width: 100%;">
            <div id="artListDiv">

            </div>
            <hr>
            <div class="blog-pagnation-wrapper">
                <button onclick="first()" class="blog-pagnation-item">首页</button>
                <button onclick="previous()" class="blog-pagnation-item">上一页</button>
                <button onclick="next()" class="blog-pagnation-item">下一页</button>
                <button onclick="final()" class="blog-pagnation-item">末页</button>
            </div>
        </div>
    </div>
<script>

    function log_out(){
        jQuery.ajax({
            url:"/user/log_out",
            type: "POST",
            data:{},
            success:function (result){
                if (result.data==1){
                    alert("退出登陆成功");
                    location.href="/reg.html";
                }
            }
        })
    }
    var allpage;
    function getpage(){
        jQuery.ajax({
            url:"/article/allpage",
            type:"POST",
            data:{},
            success:function (result){
                if (result.data>=0){
                    allpage=result.data;
                    if (result.code==800){
                        var element=document.getElementById("login")
                        element.remove()
                    }
                    return result.data;
                }
                else {
                    alert("加载错误");
                }
            }
        })
    }
    getpage();
    function getUrlValue(key){
        var params=location.search;
        if(params.length>1){
            params=location.search.substring(1);
            var paramsarr=params.split("&");
            for(var i=0;i<paramsarr.length;i++){
                var kv=paramsarr[i].split("=");
                if(kv[0]==key){
                    return kv[1]
                }
            }
            return "";
        }
    }
    var id=getUrlValue("id");
    function this_page_content(){
        jQuery.ajax({
            url:"/article/this_page_content",
            type:"POST",
            data:{"index":4,"page":id},
            success:function (result){
                if(result!=null){
                    var artListHtml = "";
                    for(var i=0;i<result.data.length;i++){
                        var articleinfo = result.data[i];
                        artListHtml +='<div class="blog">';
                        artListHtml +='<div class="title">'+articleinfo.title+'</div>';
                        artListHtml +='<h5 style="text-align: center">作者：<span id="author">'+articleinfo.username+'</span></h5>';
                        artListHtml +='<div class="date">'+articleinfo.updatetime+'</div>';
                        artListHtml +='<div class="desc">';
                        artListHtml += articleinfo.content.slice(0,100);
                        artListHtml += '<br>';
                        artListHtml += articleinfo.content.slice(101,130);
                        artListHtml += '.........';
                        artListHtml +='</div>'
                        artListHtml +='<a href="blog_list_content.html?id='+ articleinfo.id
                            +'" class="detail">查看全文 &gt;&gt;</a>';
                        artListHtml +='</div>';
                    }
                    jQuery("#artListDiv").html(artListHtml);
                }
            }
        })
    }
    this_page_content();
    function first(){
        if (id==1){
            alert("已经在首页了");
            return;
        }
        location.href="blog_list.html?id=1";
    }
    function previous(){
        if (id==1){
            alert("没有最新内容了");
            return
        }
        location.href="blog_list.html?id="+parseInt(id-1);
    }
    function next(){
        if (id==allpage){
            alert("没有更多内容了");
            return;
        }
        location.href="blog_list.html?id="+(parseInt(id)+1);
    }
    function final(){
        if (id==allpage){
            alert("已经在末页了");
            return;
        }
        location.href="blog_list.html?id="+allpage;
    }
</script>
</body>
</html>